package com.xiaoke.accountsoft.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ListAdapter;



public class MainActivity extends AppCompatActivity {
    @Override
    //创建GridView对象
    protected void onCreate(Bundle savedInstanceState) {
        GridView gvInfo;
        //定义字符串数组，存储系统功能
        String[] titles = new String[]{"新增支出", "新增收入", "我的支出", "我的收入", "数据管理",
                "系统设置", "收支便签", "退出"};
        //定义int数组，存储功能对应的图标
        int[] images = new int[]{R.drawable.addoutaccount,
                R.drawable.addinaccount, R.drawable.outaccountinfo,
                R.drawable.inaccountinfo, R.drawable.showinfo, R.drawable.sysset,
                R.drawable.accountflag, R.drawable.exit};
        /** Called when the activity is first created. */
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取布局文件中的gvInfo组件
        gvInfo = (GridView) findViewById(R.id.gvInfo);
        //创建pictureAdapter对象
        PictureAdapter adapter = new PictureAdapter(titles, images, this);
        //为GridView设置数据源
        gvInfo.setAdapter((ListAdapter) adapter);
        //为GridView设置项单击事件
        gvInfo.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                //创建Intent对象
                Intent intent = null;
                switch (arg2) {
                    case 0:
                        //使用AddOutaccount窗口初始化Intent
                        intent = new Intent(MainActivity.this, AddOutaccount.class);
                        //打开AddOutaccount
                        startActivity(intent);
                        break;
                    case 1:
                        //使用AddInaccount窗口初始化Intent
                        intent = new Intent(MainActivity.this, AddInaccount.class);
                        //打开AddInaccount
                        startActivity(intent);
                        break;
                    case 2:
                        //使用Outaccountinfo窗口初始化Intent
                        intent = new Intent(MainActivity.this, Outaccountinfo.class);
                        //打开Outaccountinfo
                        startActivity(intent);
                        break;
                    case 3:
                        //使用Inaccountinfo窗口初始化Intent
                        intent = new Intent(MainActivity.this, Inaccountinfo.class);
                        //打开Inaccountinfo
                        startActivity(intent);
                        break;
                    case 4:
                        //使用Showinfo窗口初始化Intent
                        intent = new Intent(MainActivity.this, Showinfo.class);
                        //打开Showinfo
                        startActivity(intent);
                        break;
                    case 5:
                        //使用Sysset窗口初始化Intent
                        intent = new Intent(MainActivity.this, Sysset.class);
                        //打开Sysset
                        startActivity(intent);
                        break;
                    case 6:
                        //使用Accountflag窗口初始化Intent
                        intent = new Intent(MainActivity.this, Accountflag.class);
                        //打开Accountflag
                        startActivity(intent);
                        break;
                    case 7:
                        //关闭当前Activity
                        finish();
                }
            }
        });
    }
    }






